<?php
include '../c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}

//中学  选择题:每题2分  填空题:答对一个1分  填空题（每题2分，共30分）  判断题：每题1分

$tiKU=json_decode(file_get_contents('zhongxues.txt'), true);

$sql="SELECT *  FROM `uinfo` WHERE `fen` IS NULL and zu='中学组'  ORDER BY `id`  DESC LIMIT 0,1";

$query=$mysqli->query($sql);
if($query->num_rows>0){
   $getU=$query->fetch_assoc();
   $uid=$getU['uid'];
   $phone=$getU['phone'];
   $updateId=$getU['id'];


   var_dump($getU);

   echo "<br /><br />";
   echo $uid,"........",$phone;
    echo "<br /><br />";
}else{
    exit;
}


$query=$mysqli->query("SELECT yhtj,uid,phone FROM `danxuan_z` where uid='".$uid."' and phone='".$phone."' limit 0,1 ");
var_dump($tiKU['xz']);
echo "<br />";
$fen=0;

if($query->num_rows>0){
    while ($list=$query->fetch_array()) {

        $yhtj=json_decode($list['yhtj'], true);
        foreach ($yhtj as $key => $value) {
             
             
             if ($value == $tiKU['xz'][$key]) {
                 $fen++;
                  $fen++;
                 echo "$key ... $value";
                 echo "<br />";
             }

        }
     echo "<br />";
     var_dump($list);
     
    }
    echo "<br />";

}

echo $fen;
echo "<br /><br />";




$query=$mysqli->query("SELECT yhtj,uid,phone FROM `pan_z` where uid='".$uid."' and phone='".$phone."' limit 0,1 ");
var_dump($tiKU['pan']);
echo "<br />";

if($query->num_rows>0){
    while ($list=$query->fetch_array()) {

        $yhtj=json_decode($list['yhtj'], true);
        foreach ($yhtj as $key => $value) {
             
             
             if ($value == $tiKU['pan'][$key]) {
                 $fen++;
                 echo "$key ... $value";
                 echo "<br />";
             }

        }
     echo "<br />";
     var_dump($list);
     
    }
    echo "<br />";

}


echo 'fen: .....',$fen;
echo "<br /><br />";
echo "<br /><br />";

 

$query=$mysqli->query("SELECT yhtj,uid,phone FROM `tian_z` where uid='".$uid."' and phone='".$phone."' limit 0,1 ");
var_dump($tiKU['tian']);
echo "<br />";

if($query->num_rows>0){
    while ($list=$query->fetch_array()) {

        $yhtj=json_decode($list['yhtj'], true);

        foreach ($yhtj as $key => $value) {
             echo "<br />";
             if ($value[1] == $tiKU['tian'][$key]['a']) {
                 $fen++;
                 echo "$key ... $value[1]";
                 echo "<br />";
             }
             if ($value[2] == $tiKU['tian'][$key]['b']) {
                 $fen++;
                 echo "$key ... $value[2]";
                 echo "<br />";
             }

        }
     echo "<br />";
     var_dump($list);
     
    }
    echo "<br />";
}

echo 'tian: .....',$fen;
echo "<br /><br />";

$sql="update `uinfo` set fen=".$fen." WHERE id='".$updateId."'";
$query=$mysqli->query($sql);
echo $sql;

/**

TRUNCATE danxuan_z;
TRUNCATE danxuan;
TRUNCATE pan_z;
TRUNCATE pan;
TRUNCATE tian_z;
TRUNCATE tian;


SELECT phone, COUNT(phone) as c FROM uinfo GROUP by phone HAVING c > 1

SELECT phone, COUNT(phone) as c FROM uinfo where isdel is NULL GROUP by phone HAVING c > 1

*/
?>

<script type="text/javascript">
    window.setTimeout(function(){
         window.location.reload();
    }, 600);

</script>